package com.yxhl.km.module.home.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.yxhl.km.R;
import com.yxhl.km.module.home.entity.HomeBean;
import com.yxhl.km.module.person.entity.ItemModel;
import com.yxhl.km.module.recycleradapter.ListBaseAdapter;
import com.yxhl.km.module.recycleradapter.SuperViewHolder;
import com.yxhl.km.module.utils.DateUtil;
import com.yxhl.km.module.utils.PlanState;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * Created by 张亚楠 on 2018/7/10.
 */

public class HomeAdapter extends ListBaseAdapter<HomeBean.DataBeanX.DataBean> {
    public HomeAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_task_list_new;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        HomeBean.DataBeanX.DataBean item = mDataList.get(position);

        TextView tasklist_variety_year = holder.getView(R.id.tasklist_variety_year);
        tasklist_variety_year.setText(item.getHarvestYear() + mContext.getResources().getString(R.string.year_plan));
        TextView task_rate = holder.getView(R.id.task_rate);
        task_rate.setText(new BigDecimal(item.getProduce()).divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP) + "/" + new BigDecimal(item.getExpectProduce()).divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP) + " T");
        TextView plan_state_tv = holder.getView(R.id.plan_state_tv);
        plan_state_tv.setText(PlanState.getState(mContext, item.getPlanStatus()));
        plan_state_tv.setTextColor(PlanState.getStateColor(mContext, item.getPlanStatus()));
        task_rate.setBackgroundResource(getRateColor(item.getPlanStatus()));
        TextView plan_name = holder.getView(R.id.plan_name);
        plan_name.setText(item.getFarmName() + item.getPivotNum() + mContext.getResources().getString(R.string.pivotNum));
        TextView plan_number = holder.getView(R.id.plan_number);
        plan_number.setText(mContext.getResources().getString(R.string.plan_number) + item.getPlanNum());
        TextView plan_start_time = holder.getView(R.id.plan_start_time);
        plan_start_time.setText(DateUtil.dataFormat(DateUtil.StrToDate(item.getExceptStartTime()), "MM-dd"));
        TextView plan_end_time = holder.getView(R.id.plan_end_time);
        plan_end_time.setText(DateUtil.dataFormat(DateUtil.StrToDate(item.getExceptEndTime()), "MM-dd"));
        TextView fact_start_time = holder.getView(R.id.fact_start_time);
        fact_start_time.setText(DateUtil.dataFormat(DateUtil.StrToDate(item.getStartTime()), "MM-dd"));
        TextView fact_end_time = holder.getView(R.id.fact_end_time);
        fact_end_time.setText(DateUtil.dataFormat(DateUtil.StrToDate(item.getEndTime()), "MM-dd"));
        TextView plan_variery_name = holder.getView(R.id.plan_variery_name);
        plan_variery_name.setText(item.getVarietyName());
        TextView plan_warehouse_tv = holder.getView(R.id.plan_warehouse_tv);
        plan_warehouse_tv.setText(item.getCellName() + item.getCellNum());

//        helper.setText(R.id.tasklist_variety_year, item.getHarvestYear() + mContext.getResources().getString(R.string.year_plan));
//        helper.setText(R.id.task_rate, new BigDecimal(item.getProduce()).divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP) + "/" + new BigDecimal(item.getExpectProduce()).divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP) + " T");
//        helper.setText(R.id.plan_state_tv, PlanState.getState(mContext, item.getPlanStatus()));
//
//        helper.setText(R.id.plan_name, item.getFarmName() + item.getPivotNum() + mContext.getResources().getString(R.string.pivotNum));
//        helper.setText(R.id.plan_number, mContext.getResources().getString(R.string.plan_number) + item.getPlanNum());
//        helper.setText(R.id.plan_start_time, DateUtil.dataFormat(DateUtil.StrToDate(item.getExceptStartTime()), "MM-dd"));
//
//        helper.setText(R.id.plan_end_time, DateUtil.dataFormat(DateUtil.StrToDate(item.getExceptEndTime()), "MM-dd"));
//        helper.setText(R.id.fact_start_time, DateUtil.dataFormat(DateUtil.StrToDate(item.getStartTime()), "MM-dd"));
//        helper.setText(R.id.fact_end_time, DateUtil.dataFormat(DateUtil.StrToDate(item.getEndTime()), "MM-dd"));


//        helper.setText(R.id.plan_variery_name, item.getVarietyName());
//        helper.setText(R.id.plan_warehouse_tv, item.getCellName() + item.getCellNum());
//
//
//        helper.setTextColor(R.id.plan_state_tv, PlanState.getStateColor(mContext, item.getPlanStatus()));
//        helper.setBackgroundRes(R.id.task_rate, getRateColor(item.getPlanStatus()));
        //  helper.setText(R.id.plan_variery_name,item.getVarietyName()+item.getVarietyLevel());
    }

    /**
     * 获取进度的背景颜色
     *
     * @param planStatus
     * @return
     */
    private int getRateColor(int planStatus) {
        if (planStatus == 1) {
            return R.drawable.corners_bg_green;
        } else if (planStatus == 2) {
            return R.drawable.corners_bg_grey;
        } else if (planStatus == 3) {
            return R.drawable.corners_bg_grey;
        } else {
            return R.drawable.corners_bg_main;
        }

    }
}
